package top.forgirl.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import top.forgirl.common.result.Result;
import top.forgirl.common.result.ResultType;
import top.forgirl.domain.Produce;
import top.forgirl.service.ProduceService;

import java.util.List;

@Api(tags = "成果展示模块")
@RestController
public class ProduceController {

    @Autowired
    private ProduceService produceService;

    @ApiOperation("查询成果")
    @GetMapping("/produce/{cId}/{name}/{comment}")
    public Result<List<Produce>> listProduce(@PathVariable String cId,
                                             @PathVariable String name,
                                             @PathVariable String comment) {

        List<Produce> produces = produceService.list(cId, name, comment);
        return new Result<>(produces);
    }

    @ApiOperation("删除成果")
    @DeleteMapping("/produce")
    public Result deleteProduce(String id) {
        Produce result = produceService.delete(id);
        if (result != null) {
            return new Result(result);
        }else {
            return new Result(ResultType.FAILED,"删除失败");
        }
    }

    @ApiOperation("增加成果记录")
    @PostMapping("/produce")
    public Result addProduce(@RequestBody Produce produce){
        Produce result = produceService.insert(produce);
        if(result!=null){
            return new Result(result);
        }else {
            return new Result(ResultType.FAILED,"添加失败");
        }

    }

}
